'''
Author: didiplus
Description: 
Date: 2025-08-20 20:55:19
LastEditors: didiplus
LastEditTime: 2025-08-22 15:15:22
FilePath: /WeChatBot/app/schemas/keyword.py
Version: 1.0
'''
# schemas/keyword.py
"""
Author: didiplus
Description: 关键词规则数据模型定义
Date: 2025-08-20 20:37:07
LastEditors: didiplus
LastEditTime: 2025-08-20 20:37:08
FilePath: /WeChatBot/app/schemas/keyword.py
Version: 1.0
"""
from pydantic import BaseModel, Field
from typing import Optional, List
from datetime import datetime

class KeywordRuleBase(BaseModel):
    """
    关键词规则基础模型
    """
    keyword: str = Field(..., min_length=1, max_length=255, description="关键词内容")
    response: str = Field(..., min_length=1, description="匹配后的响应内容")
    priority: Optional[int] = Field(1, ge=0, description="优先级，数值越小优先级越高")
    case_sensitive: Optional[bool] = Field(False, description="是否区分大小写")
    exact_match: Optional[bool] = Field(False, description="是否精确匹配")
    is_active: Optional[bool] = Field(None, description="是否激活")
    description: Optional[str] = Field(None, max_length=500, description="规则描述")

class KeywordRuleCreate(KeywordRuleBase):
    """
    关键词规则创建模型
    """
    pass

class KeywordRuleUpdate(BaseModel):
    """
    关键词规则更新模型
    """
    keyword: Optional[str] = Field(None, min_length=1, max_length=255, description="关键词内容")
    response: Optional[str] = Field(None, min_length=1, description="匹配后的响应内容")
    priority: Optional[int] = Field(None, ge=0, description="优先级，数值越小优先级越高")
    case_sensitive: Optional[bool] = Field(None, description="是否区分大小写")
    exact_match: Optional[bool] = Field(None, description="是否精确匹配")
    description: Optional[str] = Field(None, max_length=500, description="规则描述")
    is_active: Optional[bool] = Field(None, description="是否激活")

class KeywordRuleInDBBase(KeywordRuleBase):
    """
    关键词规则数据库基础模型
    """
    id: int = Field(..., description="规则ID")
    user_id: int = Field(..., description="用户ID")
    is_active: bool = Field(True, description="是否激活")
    created_at: Optional[datetime] = Field(None, description="创建时间")
    updated_at: Optional[datetime] = Field(None, description="更新时间")

    class Config:
        orm_mode = True

class KeywordRule(KeywordRuleInDBBase):
    """
    关键词规则返回模型
    """
    pass

class KeywordRuleInDB(KeywordRuleInDBBase):
    """
    关键词规则数据库模型
    """
    pass

class TextInput(BaseModel):
    """
    文本输入模型
    """
    text: str = Field(..., min_length=1, description="待匹配的文本")

class KeywordResponse(BaseModel):
    """
    关键词匹配响应模型
    """
    keyword: str = Field("", description="匹配到的关键词")
    response: str = Field("", description="关键词对应的响应内容")
    matched: bool = Field(False, description="是否匹配成功")
    priority: Optional[int] = Field(None, description="优先级")

class MatchResult(BaseModel):
    """
    匹配结果模型
    """
    matched_keywords: List[KeywordResponse] = Field([], description="所有匹配到的关键词")
    best_match: Optional[KeywordResponse] = Field(None, description="最佳匹配结果")